"""
This test will read in a sample data file and do some basic checks to make
sure that it conforms to the JointTrack cal format.
"""

import JTCalibration
reload(JTCalibration)

JTCal = JTCalibration.JTCalibration()

good_filename = "C:/Lib/JointTrack/branches/bryan/Tests/good_cal.txt"

JTCal.LoadFromFile(good_filename)

print ""
print "<------------------------------------------------------------->"
print "The next 4 tests should PASS successfully"
print ""

try:
    assert(abs(JTCal._FocalDistance)>=0)
    print "Test Success! Focal Distance is a valid number."
except:
    print "Test Failure! Focal Distance is NOT valid."

try:
    assert(abs(JTCal._XOffset)>=0)
    print "Test Success! X Offset is a valid number."
except:
    print "Test Failure! X Offset is NOT valid."

try:
    assert(abs(JTCal._YOffset)>=0)
    print "Test Success! Y Offset is a valid number."
except:
    print "Test Failure! Y Offset is NOT valid."

try:
    assert(abs(JTCal._PixelScale)>=0)
    print "Test Success! Pixel Scale is a valid number."
except:
    print "Test Failure! Pixel Scale is NOT valid."


bad_filename1 = "C:/Lib/JointTrack/branches/bryan/Tests/bad_cal1.txt"
bad_filename2 = "C:/Lib/JointTrack/branches/bryan/Tests/bad_cal2.txt"

print ""
print "<------------------------------------------------------------->"
print "The next command should fail (not a valid JointTrack file), but not replace the last good cal"
print ""

JTCal.LoadFromFile(bad_filename1)

print ""

print ""
print "<------------------------------------------------------------->"
print "The next command should fail (data in file is not valid), but not replace the last good cal"
print ""

JTCal.LoadFromFile(bad_filename2)

print ""


print ""
print "<------------------------------------------------------------->"
print "The next 4 tests should PASS successfully, since the original data is still in place"
print ""

try:
    assert(abs(JTCal._FocalDistance)>=0)
    print "Test Success! Focal Distance is a valid number."
except:
    print "Test Failure! Focal Distance is NOT valid."

try:
    assert(abs(JTCal._XOffset)>=0)
    print "Test Success! X Offset is a valid number."
except:
    print "Test Failure! X Offset is NOT valid."

try:
    assert(abs(JTCal._YOffset)>=0)
    print "Test Success! Y Offset is a valid number."
except:
    print "Test Failure! Y Offset is NOT valid."

try:
    assert(abs(JTCal._PixelScale)>=0)
    print "Test Success! Pixel Scale is a valid number."
except:
    print "Test Failure! Pixel Scale is NOT valid."